home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / lib / php / DB / ibase.php < prev    next >
Encoding:
PHP Script  |  2001-03-06  |  5.0 KB  |  188 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group                   |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Sterling Hughes <sterling@php.net>                          |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: ibase.php,v 1.9 2000/12/01 14:58:10 sterling Exp $
  20. //
  21. // Database independent query interface definition for PHP's Interbase
  22. // extension.
  23. //
  24.  
  25. require_once 'DB/common.php';
  26.  
  27. class DB_ibase extends DB_common {
  28.  
  29.     var $connection;
  30.     var $phptype, $dbsyntax;
  31.     var $prepare_tokens = array();
  32.     var $prepare_types = array();
  33.  
  34.     function DB_ibase() {
  35.         $this->phptype = 'ibase';
  36.         $this->dbsyntax = 'ibase';
  37.         $this->features = array(
  38.             'prepare' => true,
  39.             'pconnect' => true,
  40.             'transactions' => true
  41.         );
  42.     }
  43.  
  44.     function connect (&$dsn, $persistant=false) {
  45.         if(is_array($dsn)) {
  46.             $dsninfo = &$dsn;
  47.         } else {
  48.             $dsninfo = DB::parseDSN($dsn);
  49.         }
  50.         if (!$dsninfo || !$dsninfo['phptype']) {
  51.             return $this->raiseError(); 
  52.         }
  53.         $user = $dsninfo['username'];
  54.         $pw = $dsninfo['password'];
  55.         $dbhost = $dsninfo['hostspec'] ? 
  56.                   ($dsninfo['hostspec'] . ':/' . $dsninfo['database']) : 
  57.                   $dsninfo['database'];
  58.         $connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect';
  59.         if ($dbhost && $user && $pw) {
  60.             $conn = $connect_function($dbhost, $user, $pw);
  61.         } elseif ($dbhost && $user) {
  62.             $conn = $connect_function($dbhost, $user);
  63.         } elseif ($dbhost) {
  64.             $conn = $connect_function($dbhost);
  65.         } else {
  66.             return $this->raiseError();
  67.         }
  68.         $this->connection = $conn;
  69.         return DB_OK;
  70.     }
  71.  
  72.     function disconnect() {
  73.         return @ibase_close($this->connection);
  74.     }
  75.  
  76.     function &query( $stmt ) {
  77.         $this->last_query = $query;
  78.         $result = @ibase_query($this->connection, $stmt);
  79.         if (!$result) {
  80.             return $this->raiseError();
  81.         }
  82.         // Determine which queries that should return data, and which
  83.         // should return an error code only.
  84.         if (preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt)) {
  85.             $resultObj = new DB_result($this, $result);
  86.             return $resultObj;
  87.         } else {
  88.             return DB_OK;
  89.         }
  90.     }
  91.  
  92.     function simpleQuery($stmt) {
  93.         $this->last_query = $query;
  94.         $result = @ibase_query($this->connection, $stmt);
  95.         if (!$result) {
  96.             return $this->raiseError();
  97.         }
  98.         // Determine which queries that should return data, and which
  99.         // should return an error code only.
  100.         return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt) ? $result : DB_OK;
  101.     }
  102.  
  103.     function &fetchRow($result, $fetchmode=DB_FETCHMODE_DEFAULT) {
  104.         if ($fetchmode == DB_FETCHMODE_DEFAULT) {
  105.             $fetchmode = $this->fetchmode;
  106.         }
  107.         if ($fetchmode & DB_FETCHMODE_ASSOC) {
  108.             $row = (array)ibase_fetch_object($result);
  109.         } else {
  110.             $row = ibase_fetch_row($result);
  111.         }
  112.         if (!$row) {
  113.             return $this->raiseError();
  114.         }
  115.         return $row;
  116.     }
  117.  
  118.     function fetchInto($result, &$ar, $fetchmode=DB_FETCHMODE_DEFAULT) {
  119.         if ($fetchmode == DB_FETCHMODE_DEFAULT) {
  120.             $fetchmode = $this->fetchmode;
  121.         }
  122.         if ($fetchmode & DB_FETCHMODE_ASSOC) {
  123.             return $this->raiseError(DB_ERROR_NOT_CAPABLE);
  124.         } else {
  125.             $ar = ibase_fetch_row($result);
  126.         }
  127.         if (!$ar) {
  128.             return $this->raiseError();
  129.         }
  130.         return DB_OK;
  131.     }
  132.  
  133.     function freeResult() {
  134.         return $this->raiseError(DB_ERROR_NOT_CAPABLE);
  135.     }
  136.  
  137.     function freeQuery($query) {
  138.         ibase_free_query($query);
  139.         return true;
  140.     } 
  141.  
  142.     function numCols($result) {
  143.         $cols = ibase_num_fields($result);
  144.         if (!$cols) {
  145.             return $this->raiseError();
  146.         }
  147.         return $cols;
  148.     }
  149.  
  150.     function prepare($query) {
  151.         $this->last_query = $query;
  152.         return ibase_prepare($query);
  153.     }
  154.  
  155.     function execute($stmt, $data = false) {
  156.         $result = ibase_execute($stmt, $data);
  157.         if (!$result) {
  158.             return $this->raiseError();
  159.         }
  160.         return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt) ? $result : DB_OK;
  161.     }
  162.  
  163.     function autoCommit($onoff=false) {
  164.         return $this->raiseError(DB_ERROR_NOT_CAPABLE);
  165.     }
  166.  
  167.     function commit() {
  168.         return ibase_commit($this->connection);
  169.     }
  170.  
  171.     function rollback($trans_number) {
  172.         return ibase_rollback($this->connection,$trans_number);
  173.     }
  174.  
  175.     function transactionInit($trans_args=0) {
  176.         return $trans_args ? ibase_trans($trans_args, $this->connection) : ibase_trans();
  177.     }
  178. }
  179.  
  180. /*
  181.  * Local variables:
  182.  * tab-width: 4
  183.  * c-basic-offset: 4
  184.  * End:
  185.  */
  186.  
  187. ?>
  188.